package com.mccrea.principle.demeter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname Demeter1
 * @Description 遵循迪米特法则
 * @Date 2021/5/6 0006 19:51
 * @Created by Mccrea_Gao
 */
public class Demeter {
    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.printAllEmployees(new CollegeManager());
    }
}

/**
 * 学校总部员工
 */
class Employee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

/**
 * 学院员工
 */
class CollegeEmployee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

class CollegeManager {
    public List<CollegeEmployee> getAllEmployees() {
        List<CollegeEmployee> collegeEmployees = new ArrayList<>();
        for (int i = 0; i < 10; i ++) {
            CollegeEmployee collegeEmployee = new CollegeEmployee();
            collegeEmployee.setId("学院员工ID: " + i);
            collegeEmployees.add(collegeEmployee);
        }
        return collegeEmployees;
    }
}

/**
 * Employee， CollegeManager 是直接朋友， CollegeEmployee 不是直接朋友
 */
class SchoolManager {
    public List<Employee> getAllEmployees() {
        List<Employee> employees = new ArrayList<>();
        for (int i = 0; i < 5; i ++) {
            Employee employee = new Employee();
            employee.setId("学校员工ID: " + i);
            employees.add(employee);
        }
        return employees;
    }

    public void printAllEmployees(CollegeManager collegeManager) {
        List<CollegeEmployee> allEmployees = collegeManager.getAllEmployees();
        System.out.println("学院员工==========");
        allEmployees.forEach(s -> System.out.println(s.getId()));
        System.out.println("学校员工==========");
        List<Employee> allEmployees1 = this.getAllEmployees();
        allEmployees1.forEach(s -> System.out.println(s.getId()));
    }
}
